package com.chen;

import java.io.*;

public class FileInputStreamDemo {
    public static void main(String[] args) throws IOException {
        FileInputStream file = new FileInputStream("D:/");
        byte[] bytes= new byte[1024];
        int len;
        while ((len = file.read(bytes)) != -1){
            String str = new String(bytes, 0, len);
            System.out.println(str);
        }

        file.close();

        FileOutputStream outputStream = new FileOutputStream("D:/tet.txt");
        outputStream.write(bytes);
        outputStream.write("\r\n".getBytes());
    }

    public static void copyFile(String srcFile, String destFile) throws IOException {
        try(InputStream fis = new FileInputStream(srcFile);
            OutputStream fos = new FileOutputStream(destFile);){
            byte[] b = new byte[1024];
            int len;
            while ((len=fis.read(b))!=-1){
                fos.write(b,0,len);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
